package character.sprite.model;

import java.awt.image.BufferedImage;
import java.io.File;

import main.gui.dataobjecteditor.DataObjectEditor;

import configuration.Paths;

import character.sprite.gui.CharacterSpriteAnimator;
import data.DataTools;
import data.EditorObject;

public class CharacterStyle extends EditorObject {

	// Data object attributes
	private String display_name, type, dir_name, image_file_name;

	// Instance attributes
	private BufferedImage image;

	public CharacterStyle() {
		super();
	}

	public synchronized BufferedImage getThumbnailImage() {
		return this.getFullImage().getSubimage(0,
				CharacterSpriteAnimator.SPRITE_HEIGHT * 2,
				CharacterSpriteAnimator.SPRITE_WIDTH,
				CharacterSpriteAnimator.SPRITE_HEIGHT);
	}

	public synchronized BufferedImage getFullImage() {
		if (image == null) {
			this.image = DataTools.loadImage(Paths.resourcePath
					+ File.separator
					+ dir_name
					+ File.separator
					+ image_file_name);
		}
		return image;
	}

	@Override
	public void init() {
		this.image = null;
	}

	@Override
	protected void initDefaultData() {
		defaults.put("display_name", "New Character Style");
		defaults.put("type", "Body");
		String defaultName = DataTools.makeValidForFileName(CharacterStyle
				.getDefaultStyleForType((String) defaults.get("type")));
		defaults.put("dir_name", defaultName);
		defaults.put("image_file_name", defaultName + ".png");
	}

	@Override
	public DataObjectEditor buildDataObjectEditor() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public DataObjectEditor buildReferenceDataAttributePanel() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public boolean validateValue(String attrName, Object value) {
		// TODO Auto-generated method stub
		return false;
	}

	public static String getDefaultStyleForType(String styleType) {
		if (styleType.equals("Body")) {
			return "[[No Body]]";
		} else if (styleType.equals("Hair")) {
			return "[[No Hair]]";
		} else if (styleType.equals("Head")) {
			return "[[No Head]]";
		} else if (styleType.equals("Face")) {
			return "[[No Face]]";
		} else if (styleType.equals("Dress")) {
			return "[[No Dress]]";
		} else {
			return null;
		}
	}

}
